<?php
/**
 * Created by JetBrains PhpStorm.
 * User: evan
 * Date: 12-10-21
 * Time: 下午2:48
 * To change this template use File | Settings | File Templates.
 */
class Jwawa_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
    public function routeShutdown(Zend_Controller_Request_Abstract $request)
    {
        $controller = $this->getRequest()->getControllerName();
        $action = $this->getRequest()->getActionName();

        $controllerFormatted = Zend_Controller_Front::getInstance()->getDispatcher()->formatControllerName($controller);
        $actionFormatted = Zend_Controller_Front::getInstance()->getDispatcher()->formatActionName($action);
        //在excludeAclList
        $aclCfg = Zend_Registry::get('aclCfg');
        $actionCode = $aclCfg->excludeAclList->$controllerFormatted->$actionFormatted;
        if($actionCode != true){
            $session = new Zend_Session_Namespace();
            if (isset($session->session_bag)){
                $actionCode = $aclCfg->aclList->$controllerFormatted->$actionFormatted;
                $m = $session->session_bag->getUserActionCodeMap();
                if($m[$actionCode] != true){
                    throw new Jwawa_BusinessException('NO_PRIVILIGE');
                }
            } else {
                throw new Jwawa_BusinessException('NOT_LOGIN');
            }
        }
    }
}
